package com.woniuxy.controller;

import com.woniuxy.domain.Role;
import com.woniuxy.dto.DtoJSONResult;
import com.woniuxy.dto.DtoJSONResultCode;
import com.woniuxy.dto.DtoPermission;
import com.woniuxy.dto.DtoRole;
import com.woniuxy.service.RoleService;
import com.woniuxy.util.BeanCopyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName RoleController
 * @Description 角色控制层
 * @Author 王昊波
 * @Version 1.0
 */
@RequestMapping("/role")
@RestController
@Api(tags = "角色接口")
@Slf4j
@CrossOrigin
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("/selectRoles")
    @ApiOperation("查询所有角色")
    @RequiresPermissions({"角色权限管理"})
    public DtoJSONResult selectAllRoles() throws Exception{
        List<Role> roles = roleService.list();
        List<DtoRole> dtoRoles = BeanCopyUtil.copyListProperties(roles, DtoRole::new);
        return new DtoJSONResult(DtoJSONResultCode.SELECTROLESUCCESS.getCode(), DtoJSONResultCode.SELECTROLESUCCESS.getMessage(),null,dtoRoles);
    }
}
